`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Dependencies: 
// Engineer: Rohit Kulkarni, Vedang Vaidya
// 
// Create Date:    22:41:36 04/18/2014 
// Design Name: 
// Module Name:    icon 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: This file contains the ICON module which decides when to display the ICON
//					 and also decides which color to display at each of the pixels contained by the icon.
//
// Revision: 1.05
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////

//*********************************************************************************
//									ICON MODULE
//*********************************************************************************


module icon(
	input	[9:0]		pixel_row,
	input	[9:0]		pixel_column,
	input	[7:0] 	LocX_reg,			// X-coordinate of rojobot's location		
	input	[7:0]		LocY_reg,			// Y-coordinate of rojobot's location
	input	[7:0]		BotInfo_reg,	
	input	[1:0] 	ROM_data,
	
	output [10:0] 	ROM_addr,
	output reg [1:0]	icon
    );
	 
	wire signed [10:0] x_coord;
	wire signed [10:0] y_coord;

	//adding offset of 14 which helps in centering the BOT about the black line
	assign x_coord		=	(pixel_column	-	{LocX_reg, 1'b0, 1'b0}	+ 14);		
	assign y_coord		=	(pixel_row		-	{LocY_reg, 1'b0, 1'b0}	+ 14);
	//Upper 3 bits in the ROM address decide the orientation to display
	//									 -------------------------------------------
	//	FORMAT OF ROM ADDRESS:	| ORIENTATION | Y COORDINATE | x COORDINATE |
	//									 -------------	-----------------------------
	assign ROM_addr	=	{BotInfo_reg[2:0], y_coord[4:1], x_coord[4:1]};
	
	always @(*)
	begin 
	 //Display an icon of area 32 x 32 pixels around the location indicated by the BOTSIM
	 //The icon would not be centered around the black line and an offset needs to be added 
	 //to center the BOT about the black line which is done above
	 if(x_coord >= 0 && x_coord <= 31 && y_coord >= 0 && y_coord <= 31)
	 begin
		icon[1:0] = ROM_data;			//select colour to be displayed from the ROM			
	 end
	 else		
	 begin
		icon = 2'b00;						//else make the icon transparent to show the underlying MAP
	 end
	end			

			
endmodule
